maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=cue-cli
pkgver=0.10.1
pkgrel=0
pkgdesc="CLI for CUE configuration and validation language"
url="https://cuelang.org/"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
options="net" # download Go modules
source="$pkgname-$pkgver.tar.gz::https://github.com/cue-lang/cue/archive/refs/tags/v$pkgver.tar.gz
	0001-fix-tests-32bit.patch::https://github.com/cue-lang/cue/commit/8b2affe90d116314ab67a668b2aa77981066edaa.patch
	0002-fix-tests-32bit.patch
	"
builddir="$srcdir/cue-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build -v -o bin/cue \
		-ldflags "-X cuelang.org/go/cmd/cue/cmd.version=v$pkgver" \
		./cmd/cue/

	for shell in bash fish zsh; do
		./bin/cue completion $shell > cue.$shell
	done
}

check() {
	# Use a directory outside aports repository for test artifacts to pass TestScript test case.
	# (the test expects `git VCS not found in any parents of ".+"` message in stderr)
	unset GOTMPDIR

	go test ./...
}

package() {
	install -Dm755 bin/cue -t "$pkgdir"/usr/bin/

	install -Dm644 cue.bash \
		"$pkgdir"/usr/share/bash-completion/completions/cue
	install -Dm644 cue.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/cue.fish
	install -Dm644 cue.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_cue
}

sha512sums="
e4fbb2b9607534ea742b047146819f281a09eaf0ec22268cb4cb061b7ee747babeeb2e416a2c96d477334cd2211bc1fd0a426796f5c5481c400a79f8a9de00ae  cue-cli-0.10.1.tar.gz
634fc32399aa484f58cec055cbfefa63e4356c54e33a6f22e10d71a2b8174194ab6115fba05f3b799a108461f0545e676e1409e44adec2281c2f31914b608d26  0001-fix-tests-32bit.patch
d091c28b292a86aea83303971f463d9de3f4aa5ce9b2773612e1b9dc63c7fb092ca431c447af28145b35950f4c811e3e89099ae5a5ed742a480f4eca3f6aa749  0002-fix-tests-32bit.patch
"
